package com.ruoyi.biz.utils;

import com.ruoyi.biz.domain.BizSector;
import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author tianl
 * @date 2025/2/25
 * @description:
 */
public class StatUtils {
    public static List<BizSector> pack(Long parentId, List<BizSector> all) {
        List<BizSector> result = new ArrayList<>();
        List<BizSector> childList = all.stream()
                .filter(r -> r.getParentId().equals(parentId))
                .collect(Collectors.toList());
        if (!CollectionUtils.isEmpty(childList)) {
            for (BizSector child : childList) {
                result.addAll(pack(child.getId(), all));
            }
            result.addAll(childList);
        }
        return result;
    }
}
